package com.project.yunshitong.utils;

import android.util.TimeUtils;

import java.util.Timer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程管理类
 *
 * @author lenovo
 */
public class ThreadPoolManager {
    private ExecutorService service;

    private ThreadPoolManager() {
        /*int num = Runtime.getRuntime().availableProcessors() * 20;
        service = new ThreadPoolExecutor(1, 1,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(1024), r -> null, new ThreadPoolExecutor.AbortPolicy());*/
        int num = Runtime.getRuntime().availableProcessors() * 20;
        service = Executors.newFixedThreadPool(num);
    }

    private static final ThreadPoolManager MANAGER = new ThreadPoolManager();

    public static ThreadPoolManager getInstance() {
        return MANAGER;
    }

    public void executeTask(Runnable runnable) {
        service.execute(runnable);
    }

}
